package com.crm.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.crm.model.mpojo.Repairorders;
import com.crm.model.mpojo.Repairrecord;
import com.crm.model.mpojo.Tasks;
import com.crm.model.pojo.Dictionary;
import com.crm.services.ContactServices;
import com.crm.services.CustomerServices;
import com.crm.services.DictionaryServices;
import com.crm.services.OrderInfoServers;
import com.crm.services.OrderitemsServices;
import com.crm.services.ProductServices;
import com.crm.services.RepairForProduceServices;
import com.crm.services.RepairServices;
import com.crm.services.RepairrecordServices;
import com.crm.services.TaskServices;
import com.crm.services.UserServices;
import com.crm.util.LoginUtil;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/aftersale")
public class RepairController {

	@Autowired
	RepairServices repairServices;
	@Autowired
	UserServices userservices;
	@Autowired
	CustomerServices customerServices;
	@Autowired
	DictionaryServices dictionaryServices;
	@Autowired
	ContactServices contactServices;
	@Autowired
	ProductServices productServices;
	@Autowired
	OrderitemsServices orderitemsServices;
	@Autowired
	OrderInfoServers orderinforServices;
	@Autowired
	RepairrecordServices repairrecordServices;
	@Autowired
	RepairForProduceServices repairForProduceServices;
	@Autowired
	TaskServices taskServices;
	
	/**
	 * 分页查询所有维修工单
	 * @return
	 */
	@GetMapping("/repair")
	public ModelAndView findrepair(Integer pageNum, Integer pageSize,Integer statueID,String search) {
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 6;
		ModelAndView mv = new ModelAndView("/aftersale/repair");
		System.out.println("维修工单！");
		//查询分页维修工单
		List<Map<String, String>> selectPage = repairServices.selectPage(pageNum, pageSize, statueID, search);
		String jsonString = JSONObject.toJSONString(selectPage);
		System.out.println(jsonString);
		//获取分页信息
		PageInfo<Map<String, String>> page = new PageInfo<Map<String, String>>(selectPage);
		System.out.println(page);
		String pageInfo = JSONObject.toJSONString(page);
		System.out.println(page);
		mv.addObject("list", jsonString);
		mv.addObject("page", page);
		mv.addObject("pageinfo", pageInfo);
		return mv;
	}
	
	/**
	 * 分页查询获取工单（刷新表单）
	 * @param pageNum
	 * @param pageSize
	 * @param statueID
	 * @param search
	 * @return
	 */
	@RequestMapping("/repairNew")
	@ResponseBody	
	public PageInfo<Map<String, String>> findrepairNew(Integer pageNum, Integer pageSize,Integer statueID,String search) {
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 4;
		//查询分页维修工单
		System.out.println("RepairNew:"+pageNum+"\t"+pageSize+"\t"+statueID+"\t"+search);
		List<Map<String, String>> selectPage = repairServices.selectPage(pageNum, pageSize, statueID, search);
		//获取分页信息
		PageInfo<Map<String, String>> page = new PageInfo<Map<String, String>>(selectPage);
		return page;
	}
	
	/**
	 * 查询单条
	 * @param roid
	 * @return
	 */
	@PostMapping("/repairOne")
	@ResponseBody
	public JSONObject getRepairByid(@RequestParam("ID") Integer roid) {
		//根据工单编号查询单条
		Map<String, String> repair = repairServices.selectByid(roid);
		JSONObject jsonObject = new JSONObject();
		System.out.println("单条工单信息:"+repair);
		jsonObject.put("repair", repair);//工单所有信息
		//id查询工单
		Map<String, String> findByid = repairServices.selectByidOne(roid);
		System.out.println("id查询 ："+findByid);
		if (findByid.get("custid")!=null) {
			Object object = findByid.get("custid");
			System.out.println(Integer.valueOf(object.toString()));
			//查询工单对应客户
			Map<String, String> customer = customerServices.findByCustId(Integer.valueOf(object.toString()));
			System.out.println(customer);
			jsonObject.put("customer", customer);
		}
		//查询工单对应联系人信息
		if (findByid.get("conid")!=null) {
			List<Map<String, String>> contract = contactServices.selectcustTocon(Integer.parseInt(String.valueOf(findByid.get("conid"))));
			jsonObject.put("contract", contract);
		}
		//根据客户查询订单表信息
		List<Map<String, String>> orderByidInfo = orderinforServices.selectAllBycustIDTwo(Integer.parseInt(String.valueOf(findByid.get("custid"))));
		System.out.println("订单表信息："+orderByidInfo);
		jsonObject.put("orderByidInfo", orderByidInfo);// 订单表信息
		// 查询所有客户
		List<Map<String, String>> allCustomerName = customerServices.selectAllCustomer();
		System.out.println("客户名：" + allCustomerName);
		// 查询所有用户名
		List<Map<String, String>> allusername = userservices.selectUserAll();
		System.out.println("所有用户:" + allusername);
		// 查询维修部所有承接人
		List<Map<String, String>> workerName = userservices.selectWorkerAll(8);
		System.out.println("所有承接人:" + workerName);
		// 查询工单状态
		List<Dictionary> repairStatue = dictionaryServices.findByDictParentid(1260);
		System.out.println("工单状态：" + repairStatue);
		// 查询保修状态
		List<Dictionary> protectStatue = dictionaryServices.findByDictParentid(1263);
		System.out.println("保修状态：" + protectStatue);
		// 查询工单进度
		List<Dictionary> progressStatue = dictionaryServices.findByDictParentid(1430);
		System.out.println("工单进度：" + progressStatue);
		// 查询工单分类
		List<Dictionary> classityRepair = dictionaryServices.findByDictParentid(1079);
		System.out.println("工单分类：" + classityRepair);
		// 查询所有产品
		List<Map<String, String>> allProduce = productServices.selectAllProduce();
		System.out.println("所有产品：" + allProduce);
		// 查询保修状态
		List<Dictionary> guarantee = dictionaryServices.findByDictParentid(1260);
		System.out.println("保修状态：" + guarantee);
		
		jsonObject.put("getPerson", allusername);
		jsonObject.put("workerName", workerName);
		jsonObject.put("custid", allCustomerName);
		jsonObject.put("repairStatue", repairStatue);
		jsonObject.put("protectStatue", protectStatue);
		jsonObject.put("progressStatue", progressStatue);
		jsonObject.put("classityRepair", classityRepair);
		jsonObject.put("allProduce", allProduce);
		jsonObject.put("guarantee", guarantee);
		jsonObject.put("orderByidInfo", orderByidInfo);
		//查询维修工单分类
		List<Dictionary> reClassity = dictionaryServices.findByDictParentid(1254);
		jsonObject.put("reClassity", reClassity);
		
		return jsonObject;
	}
	
	/**
	 * 跳转维修工单视图
	 * @return
	 */
	@GetMapping("/openRepairView")
	public ModelAndView openView(Integer id) {
		System.out.println("维修工单视图！");
		ModelAndView mv = new ModelAndView("/aftersale/repairView");
		//jpa查询工单
		Map<String, String> repairOne = repairServices.selectByid(id);
		List<Map<String, String>> selectById = repairrecordServices.selectByID(id);
		//产品列表
		List<Map<String, String>> productAllPage = orderitemsServices.productAllPage();
		System.out.println("所有产品："+productAllPage);
		System.out.println("工单明细："+selectById);
		System.out.println("repairOne:"+repairOne);
		//查询工单对应的配件详情
		List<Map<String, String>> selectByRid = repairForProduceServices.selectByRid(id);
		System.out.println("配件详情："+selectByRid);
		mv.addObject("repairProductItem", JSONObject.toJSONString(selectByRid));
		if (selectById.size()!=0) {
			mv.addObject("repairrecordOne", selectById.get(0));
		}
		mv.addObject("repairOne", repairOne);
		mv.addObject("allProduce", JSONObject.toJSONString(productAllPage));
		return mv;
	}
	
	@PostMapping("/selectProduceOne")
	@ResponseBody
	public JSONObject selectProduceOne(@RequestParam("search") String search) {
		JSONObject jsonObject = new JSONObject();
		List<Map<String, String>> productAllTable = productServices.productAllTable(search);
		jsonObject.put("productAllTable", productAllTable);
		return jsonObject;
		
	}
	
	/**
	 * id逻辑删除
	 * 
	 * @param complaintId
	 * @return
	 */
	@RequestMapping("/deleteOneRepair")
	@ResponseBody
	public JSONObject deleteone(@RequestParam("ID") Integer id) {
		System.out.println("删除单个:" + id);
		//判断工单是否执行完成(工单状态和工单进度)
		List<Map<String, String>> repair = repairServices.findByidelete(id);
		System.out.println("12332"+repair);
		JSONObject jsonObject = new JSONObject();
		for (Map<String, String> map : repair) {
			String schedule = String.valueOf(map.get("schedule"));
			//String rosatus = String.valueOf(map.get("rosatus"));
			System.out.println("工单进度："+schedule);
			//schedule.equals("1265") &&
			if (schedule.equals("1436")) {
				repairServices.deleteByStatue(id);
			} else if (schedule==null || schedule=="" || "null".equals(schedule)) {
				repairServices.deleteByStatue(id);
			}
				//jsonObject.put("RoStatus", rosatus);
				jsonObject.put("RoSchedule", schedule);
		}
		return jsonObject;
	}
	
	/**
	 * 根据客户编号查询联系人及订单信息
	 * 
	 * @param conName
	 */
	@RequestMapping("/custToSelectInfo")
	@ResponseBody
	public JSONObject selectcusttocon(@RequestParam("custid") Integer custid) {
		//根据客户查询联系人
		List<Map<String, String>> selectcustTocon = contactServices.selectcustTocon(custid);
		System.out.println("联系人："+selectcustTocon);
		//根据客户查询订单表信息
		List<Map<String, String>> orderByidInfo = orderinforServices.selectAllBycustIDTwo(custid);
		System.out.println("订单表信息："+orderByidInfo);
		//根据订单编号查询订单详情表
	//	Map<String, String> orderitemsInfo = orderitemsServices.custByOrderitemsInfo(Integer.parseInt(String.valueOf(orderByidInfo.get("o_id"))));
	//	System.out.println("订单明细表信息："+orderitemsInfo);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("comcustmanid", selectcustTocon);// 联系人
		jsonObject.put("orderByidInfo", orderByidInfo);// 订单表信息
	//	jsonObject.put("orderitemsInfo", orderitemsInfo);// 订单详表信息
		return jsonObject;
	}

	/**
	 * 根据订单编号查询订单详情表信息及产品信息
	 * 
	 */
	@RequestMapping("/oidToSelectOrderitemsInfo")
	@ResponseBody
	public JSONObject selectOrderitemsInfo(@RequestParam("oid") Integer oid) {
		//根据订单编号查询订单详情表
		List<Map<String, String>> orderitemsInfo = orderitemsServices.custByOrderitemsInfo(oid);
		System.out.println("订单明细表信息："+orderitemsInfo);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("orderitemsInfo", orderitemsInfo);// 订单详表信息
		return jsonObject;
	}

	
	/**
	 * 新增时查询对应可选数据
	 * 
	 * @return
	 */
	@PostMapping("/chooseAllRepairOptions")
	@ResponseBody
	public JSONObject addoptions() {
		// 查询所有客户
		List<Map<String, String>> allCustomerName = customerServices.selectAllCustomer();
		System.out.println("客户名：" + allCustomerName);
		// 查询所有用户名
		List<Map<String, String>> allusername = userservices.selectUserAll();
		System.out.println("所有用户:" + allusername);
		// 查询维修部所有承接人
		List<Map<String, String>> workerName = userservices.selectWorkerAll(8);
		System.out.println("所有承接人:" + workerName);
		// 查询工单状态
		List<Dictionary> repairStatue = dictionaryServices.findByDictParentid(1260);
		System.out.println("工单状态：" + repairStatue);
		// 查询保修状态
		List<Dictionary> protectStatue = dictionaryServices.findByDictParentid(1263);
		System.out.println("保修状态：" + protectStatue);
		// 查询工单进度
		List<Dictionary> progressStatue = dictionaryServices.findByDictParentid(1430);
		System.out.println("工单进度：" + progressStatue);
		// 查询工单分类
		List<Dictionary> classityRepair = dictionaryServices.findByDictParentid(1079);
		System.out.println("工单分类：" + classityRepair);
		// 查询所有产品
		List<Map<String, String>> allProduce = productServices.selectAllProduce();
		System.out.println("所有产品：" + allProduce);
		// 查询保修状态
		List<Dictionary> guarantee = dictionaryServices.findByDictParentid(1260);
		System.out.println("保修状态：" + guarantee);
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("getPerson", allusername);
		jsonObject.put("workerName", workerName);
		jsonObject.put("custid", allCustomerName);
		jsonObject.put("repairStatue", repairStatue);
		jsonObject.put("protectStatue", protectStatue);
		jsonObject.put("progressStatue", progressStatue);
		jsonObject.put("classityRepair", classityRepair);
		jsonObject.put("allProduce", allProduce);
		jsonObject.put("guarantee", guarantee);
		jsonObject.put("user", LoginUtil.getUser());
		return jsonObject;
	}
	
	@PostMapping("/addrepair")
	@ResponseBody
	public String addrepair(@RequestParam(name = "getPerson", required = false) Integer getPerson,
			@RequestParam(name = "custid", required = false) Integer custid,
			@RequestParam(name = "contactid", required = false) Integer conID,
			@RequestParam(name = "gettoday", required = false) String gettoday,
			@RequestParam(name = "phone", required = false) String repphone,
			@RequestParam(name = "gettime", required = false) String gettime,
			@RequestParam(name = "repname", required = false) String repname,
			@RequestParam(name = "gdchlassity", required = false) Integer gdchlassity,
			@RequestParam(name = "reptel", required = false) String reptel,
			@RequestParam(name = "allorders", required = false) Integer allorders,
			@RequestParam(name = "proID", required = false) String proID,
			@RequestParam(name = "getman", required = false) Integer getman,
			@RequestParam(name = "prosalettoday", required = false) String prosalettoday,
			@RequestParam(name = "texterrorDescription", required = false) String texterrorDescription,
			@RequestParam(name = "alljindu", required = false) Integer alljindu,
			@RequestParam(name = "textcommunication", required = false) String textcommunication,
			@RequestParam(name = "radioguarantee", required = false) Integer radioguarantee,
			@RequestParam(name = "rocost", required = false) BigDecimal rocost,
			@RequestParam(name = "hasgetcost", required = false) BigDecimal hasgetcost,
			@RequestParam(name = "radiostatus", required = false) Integer radiosatus,
			@RequestParam(name = "paytoday", required = false) String paytoday,
			//@RequestParam(name = "roprofit", required = false) BigDecimal roprofit,
			@RequestParam(name = "remark", required = false) String remark) throws ParseException {
		// 转换日期格式
		Repairorders repairorder = new Repairorders();
		System.out.println("日期"+gettoday+"\t"+gettime+"\t"+prosalettoday+"\t"+paytoday);
		if (gettoday!=null) {
			java.sql.Date get = java.sql.Date.valueOf(gettoday.substring(0, 10));
			repairorder.setRoGetdate(get);//接件日期
		}
		if (prosalettoday!=null) {
			java.sql.Date sale = java.sql.Date.valueOf(prosalettoday.substring(0, 10));
		}
		if (paytoday!=null) {
			java.util.Date pay = java.sql.Date.valueOf(paytoday.substring(0, 10));
			repairorder.setRoPaydate(pay);//约定交付日期
		}
		if (gettime!=null) {
			Time time = java.sql.Time.valueOf(gettime);
			repairorder.setRoGettime(time);//接件时间
		}
		//设置维修工单流水号
		String id= UUID.randomUUID().toString();
		// 添加
		repairorder.setRoGetperson(getPerson);//接单人
		repairorder.setRoWorker(getman);//承接人
		repairorder.setCustId(custid);//客户编号
		repairorder.setConId(conID);//联系人编号
		repairorder.setRoClassify(gdchlassity);//工单分类
		repairorder.setRoName(id);//流水号
		repairorder.setRoTel(reptel);;//电话
		repairorder.setRoPhone(repphone);//手机号码
		repairorder.setRoOrderid(allorders);//订单编号
		repairorder.setRoGoodid(proID);;//产品编号
		repairorder.setRoGuarantee(radioguarantee);//保修
		repairorder.setErrorDescription(texterrorDescription);//故障描述
		repairorder.setRoCommunication(textcommunication);//沟通要点注意事项
		repairorder.setRoSchedule(1431);//工单进度
		if (rocost!=null || !"".equals(rocost) ) {
			System.out.println(1);
			repairorder.setRoCost(rocost);//费用
		}else {
			repairorder.setRoCost(new BigDecimal("0.00"));//费用
			System.out.println(2);
		}
		if (hasgetcost!=null || !"".equals(hasgetcost) ) {
			System.out.println(1);
			repairorder.setRoGetCost(hasgetcost);//已收款
		}else {
			repairorder.setRoGetCost(new BigDecimal("0.00"));//已收款
			System.out.println(2);
		}
		repairorder.setRoStatus(radiosatus);//工单状态
		//repairorder.setRoProfit(roprofit);//毛利
		repairorder.setRemark(remark);//备注
		repairorder.setDeleteStatue(1206);// 状态
		int addRepair = repairServices.addRepair(repairorder);
		System.out.println("添加：" + addRepair);
		return "添加！";
	}
	
	@PostMapping("/updaterepair")
	@ResponseBody
	public String updaterepair(@RequestParam(name = "ID") Integer rid,
			@RequestParam(name = "getPerson", required = false) Integer getPerson,
			@RequestParam(name = "custid", required = false) Integer custid,
			@RequestParam(name = "contactid", required = false) Integer conID,
			@RequestParam(name = "gettoday", required = false) String gettoday,
			@RequestParam(name = "phone", required = false) String repphone,
			@RequestParam(name = "gettime", required = false) String gettime,
			@RequestParam(name = "repname", required = false) String repname,
			@RequestParam(name = "gdchlassity", required = false) Integer gdchlassity,
			@RequestParam(name = "reptel", required = false) String reptel,
			@RequestParam(name = "allorders", required = false) Integer allorders,
			@RequestParam(name = "proID", required = false) String proID,
			@RequestParam(name = "getman", required = false) Integer getman,
			@RequestParam(name = "prosalettoday", required = false) String prosalettoday,
			@RequestParam(name = "texterrorDescription", required = false) String texterrorDescription,
			@RequestParam(name = "alljindu", required = false) Integer alljindu,
			@RequestParam(name = "textcommunication", required = false) String textcommunication,
			@RequestParam(name = "radioguarantee", required = false) Integer radioguarantee,
			@RequestParam(name = "rocost", required = false) BigDecimal rocost,
			@RequestParam(name = "hasgetcost", required = false) BigDecimal hasgetcost,
			@RequestParam(name = "radiostatus", required = false) Integer radiosatus,
			@RequestParam(name = "paytoday", required = false) String paytoday,
			//@RequestParam(name = "roprofit", required = false) BigDecimal roprofit,
			@RequestParam(name = "remark", required = false) String remark) {
		Repairorders repairorder = new Repairorders();
		// 转换日期格式
		System.out.println(gettoday+gettime+prosalettoday+paytoday);
		if (gettoday!=null) {
			java.sql.Date get = java.sql.Date.valueOf(gettoday.substring(0, 10));
			repairorder.setRoGetdate(get);//接件日期
		}
		if (prosalettoday!=null) {
			java.sql.Date sale = java.sql.Date.valueOf(prosalettoday.substring(0, 10));
		}
		if (paytoday!=null) {
			java.util.Date pay = java.sql.Date.valueOf(paytoday.substring(0, 10));
			repairorder.setRoPaydate(pay);//约定交付日期
		}
		if (gettime!=null) {
			Time time = java.sql.Time.valueOf(gettime);
			repairorder.setRoGettime(time);//接件时间
		}
		// 修改
		repairorder.setRoId(rid);//编号
		repairorder.setRoGetperson(getPerson);//接单人
		repairorder.setRoWorker(getman);//承接人
		repairorder.setCustId(custid);//客户编号
		repairorder.setConId(conID);//联系人编号
		repairorder.setRoClassify(gdchlassity);//工单分类
		repairorder.setRoName(repname);//姓名
		repairorder.setRoTel(reptel);;//电话
		repairorder.setRoPhone(repphone);//手机号码
		repairorder.setRoOrderid(allorders);//订单编号
		repairorder.setRoGoodid(proID);;//产品编号
		repairorder.setRoGuarantee(radioguarantee);//保修
		repairorder.setErrorDescription(texterrorDescription);//故障描述
		repairorder.setRoCommunication(textcommunication);//沟通要点注意事项
		repairorder.setRoSchedule(alljindu);//工单进度
		if (rocost!=null || !"".equals(rocost) ) {
			System.out.println(1);
			repairorder.setRoCost(rocost);//费用
		}else {
			repairorder.setRoCost(new BigDecimal("0.00"));//费用
			System.out.println(2);
		}
		if (hasgetcost!=null || !"".equals(hasgetcost)) {
			System.out.println(1);
			repairorder.setRoGetCost(hasgetcost);//已收款
		}else {
			repairorder.setRoGetCost(new BigDecimal("0.00"));//已收款
			System.out.println(2);
		}
		if (alljindu==1436) {
			repairorder.setRoStatus(1265);
		}else {
			repairorder.setRoStatus(radiosatus);//工单状态
		}
		//repairorder.setRoProfit(roprofit);//毛利
		repairorder.setRemark(remark);//备注
		int addRepair = repairServices.updateRepair(repairorder);
		System.out.println("编辑：" + addRepair);
		return "编辑！";
	}
	
	/**
	 * 更新工单进度
	 * @param rid
	 * @param schedule
	 * @return
	 */
	@PostMapping("/updateSchedule")
	@ResponseBody
	public String updaterepairSchedule(@RequestParam(name = "ID") Integer rid,
		//@RequestParam(name = "textcommunication", required = false) String textcommunication,
		@RequestParam(name = "newresult", required = false) Integer schedule) {
		Repairorders repairorder = new Repairorders();
		repairorder.setRoId(rid);//编号
		repairorder.setRoSchedule(schedule);//状态
		if (schedule==1436) {
			repairorder.setRoStatus(1265);
		}
		//repairorder.setRoCommunication(textcommunication);//沟通要点注意事项
		System.out.println("更新状态："+rid+"----"+schedule);
		int addRepair = repairServices.updateRepair(repairorder);
		return "更新状态！";
	}
	
	/**
	 * 导出
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "RepairExcelDownloads", method = RequestMethod.GET)
    public void downloadAllClassmate(HttpServletResponse response) throws IOException {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("维修工单！");

        List<Map<String, String>> selectAll = repairServices.selectalInfo();
      
        String fileName = "repairinfo"  + ".xls";//设置要导出的文件的名字
        //新增数据行，并且设置单元格数据

        int rowNum = 1;

        String[] headers = { "编号","接单人","维修员","主题","客户","联系人","接件日期","接件时间","工单分类","订单编号","维修产品","保修", "费用", "已收款","工单进度","状态","故障描述","沟通要点注意事项"};
        //headers表示excel表中第一行的表头

        HSSFRow row = sheet.createRow(0);
        //在excel表中添加表头

        for(int i=0;i<headers.length;i++){
            HSSFCell cell = row.createCell(i);
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);
        }

        //在表中存放查询到的数据放入对应的列
        for (Map<String, String> map : selectAll) {
        	HSSFRow row1 = sheet.createRow(rowNum);
            row1.createCell(0).setCellValue(String.valueOf(map.get("ID")));
            row1.createCell(1).setCellValue(map.get("getpersonName"));
            row1.createCell(2).setCellValue(map.get("workerName"));
            row1.createCell(3).setCellValue(String.valueOf(map.get("theme")));
            row1.createCell(4).setCellValue(String.valueOf(map.get("custName")));
            row1.createCell(5).setCellValue(String.valueOf(map.get("conName")));
            row1.createCell(6).setCellValue(String.valueOf(map.get("getDate")));
            row1.createCell(7).setCellValue(String.valueOf(map.get("getTime")));
            row1.createCell(8).setCellValue(String.valueOf(map.get("classifyName")));
            row1.createCell(9).setCellValue(String.valueOf(map.get("roOrderid")));
            row1.createCell(10).setCellValue(map.get("goodName"));
            row1.createCell(11).setCellValue(map.get("guaranteeName"));
            row1.createCell(12).setCellValue(String.valueOf(map.get("cost")));
            row1.createCell(13).setCellValue(String.valueOf(map.get("getCost")));
            row1.createCell(14).setCellValue(map.get("scheduleName"));
            row1.createCell(15).setCellValue(map.get("statusName"));
            row1.createCell(16).setCellValue(map.get("errorDescription"));
            row1.createCell(17).setCellValue(map.get("communication"));
            rowNum++;
      		}
              
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }
	
}
